# -*- coding:utf-8 -*-

from django.contrib.auth.forms import UserCreationForm

from django.forms import *
from advertising_app.models import Author

class AuthorCreationForm(UserCreationForm):
    email = EmailField(label="Adres e-mail",required=True)
    first_name = CharField(label=u"Imię",required=True)
    last_name = CharField(label="Nazwisko",required=True)
    phone_number = CharField(label="Nr telefonu",required=False)
    
    def save(self):
        new_user = super(AuthorCreationForm,self).save(commit=False)
        cd = self.cleaned_data
        new_user.email = cd["email"]
        new_user.first_name = cd["first_name"]
        new_user.last_name = cd["last_name"]
        new_user.save()
        Author(phone=cd["phone_number"],user=new_user).save()
        return new_user
    
class AdvertisementSearchForm(forms.Form):
    city = CharField(max_length = 50,required=False,label="Miasto")
    street = CharField(max_length= 50,required=False,label="Ulica")
    
class NewAdvertisementForm(forms.Form):
    city = CharField(max_length = 50,label="Miasto")
    street = CharField(max_length = 50,label="Ulica")
    house_number= IntegerField(required=False,label="Numer domu")
    description = CharField(required=True, widget=forms.Textarea, label='Podaj opis', 
                           error_messages={'required': 'Wpisz jakąś wartość!!'})
    show_contact_data = BooleanField(label="Wyświetlać kontakt do Ciebie?")